 var count = null;
//查看大图
function xiaotu(svId){
	 $("#pic_a_image" ).css("display", "none");
	 $("#page_cover").animate({opacity: "0"}, 300, function(){
	 	$("#page_cover").hide();
	 });
}
function findBigImg(imgUrl,svId){
	$("#pic_a_image").empty();
	count = null;
	 $("#page_cover").show().animate({opacity: "0.5"}, 300);
	 $("#pic_a_image").css("display", "block");	
	 var srceenWidth = $(window).width();
	 var srceenHeight = $(window).height();
	 var newImgUrl = imgUrl.replace("middle", "original");
	 $("#saveImage").attr("src", newImgUrl);
	  count="<table onclick='xiaotu("+svId+");' style='width:"+srceenWidth+"px;height:"+srceenHeight+"px;' class='tanchu_img'><tr><td style='width:"+srceenWidth+"px;height:"+srceenHeight+"px;position:relative;'>"; 
	 count +="<img class='rot0' style='visibility:hidden;' id=p_"+svId+" src='"+ newImgUrl +"' onload='resizeImg();' />";	 
	 count += "</td></tr></table>";
	 count +="<div class='tanchu_img_bg'></div>";
	 count +="<div class='tanchu_img_ctrl'>";
	 count +="<a href='###' onclick=\'rotateRight()\' title='左旋'><img src='public/images/t_lf.png'/></a>";
	 count +="<a style='margin:0 10px 0 20px;' href='###' title='右旋' onclick=\'rotateLeft()\'><img src='public/images/t_rt.png'/></a>";
	 count +="<a  style='margin:0 10px 0 20px;'  href='###' title='查看原图' onclick=\'openbigImg("+svId+")\'><img src='public/images/t_fd.png'/></a>";
	 count +="<a style='margin:0 10px 0 20px;' href='messages/getPictrue?picurl="+newImgUrl+"' title='保存' ><img src='public/images/save.png'/></a>";
	 count +="<a style='margin:0 10px 0 20px;' href='javascript:void(0);' title='关闭' onclick='xiaotu("+svId+");'><img src='public/images/t_close.png'/></a>"; 
	 count += "</div>";	 
	 setTimeout("test()", 1000);
}

function test(){	
	$("#pic_a_image").html(count);
}

function resizeImg(){
	var srceenWidth = $(window).width();
	var srceenHeight = $(window).height();
	var imgWidth = $(".tanchu_img td img").width();
	var imgHeight = $(".tanchu_img td img").height();
	var srceenScale = srceenWidth/srceenHeight;
	var imgScale = imgWidth/imgHeight;
	if(imgWidth>srceenWidth||imgHeight>srceenHeight){
		if(srceenScale>=imgScale){
			$(".tanchu_img td img").css("height", srceenHeight);
		}
		if(srceenScale<imgScale){
			$(".tanchu_img td img").css("width", srceenHeight);
		}
	}
	$(".tanchu_img td img").css("visibility", "visible");
}

function ieImgPosition(){
	var srceenWidth = $(window).width();
	var srceenHeight = $(window).height();
	var imgWidth = $(".tanchu_img td img").width();
	var imgHeight = $(".tanchu_img td img").height();
	$(".tanchu_img td img").css('position', "absolute");
	$(".tanchu_img td img").css('z-index', 11);
	$(".tanchu_img td img").css('top', (srceenHeight-imgWidth)/2);
	$(".tanchu_img td img").css('left', (srceenWidth-imgHeight)/2);
}

function rotateRight() {
	if($.browser.msie){
		ieImgPosition();
	}
	if($(".tanchu_img td img").hasClass("rot0")){
		$(".tanchu_img td img").attr('class','rot3');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot1")){
		$(".tanchu_img td img").attr('class','rot0');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot2")){
		$(".tanchu_img td img").attr('class','rot1');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot3")){
		$(".tanchu_img td img").attr('class','rot2');
		return(false);
	}
}

function rotateLeft() {
	if($.browser.msie){
		ieImgPosition();
	}
	if($(".tanchu_img td img").hasClass("rot0")){
		$(".tanchu_img td img").attr('class','rot1');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot1")){
		$(".tanchu_img td img").attr('class','rot2');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot2")){
		$(".tanchu_img td img").attr('class','rot3');
		return(false);
	}
	if($(".tanchu_img td img").hasClass("rot3")){
		$(".tanchu_img td img").attr('class','rot0');
		return(false);
	}
}	
function openbigImg(svid){
	var imgurl = document.getElementById("p_"+svid);
	window.open(imgurl.src);
}